package com.zhang.spark_1.spark_core.operator.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{HashPartitioner, SparkConf, SparkContext}

/**
 * @title:
 * @author: zhang
 * @date: 2021/12/5 18:51 
 */
object Spark14_RDD_Operator_Transform {

  def main(args: Array[String]): Unit = {
    //获取spark的连接
    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("operator")
    val sc: SparkContext = new SparkContext(conf)
    //TODO  partitionBy

    val rdd: RDD[(String, Int)] = sc.makeRDD(List(
      ("a", 1), ("a", 2), ("a", 3), ("b", 4)
    ),2)
    rdd.partitionBy(new HashPartitioner(2)).saveAsTextFile("output2")
    sc.stop()
  }
}
